package com.study.concurrentprogramming.memorySync;

import lombok.SneakyThrows;

import java.io.File;
import java.util.concurrent.TimeUnit;

/**
 * @Description :
 * @Author : guxuemin
 * @Version : V1.0.0
 * @Date : 2022/5/10 16:15
 */
public class MemorySync {
    public static void main(String[] args) throws InterruptedException {
        ThreadDemo threadDemo = new ThreadDemo();
        new Thread(threadDemo, "t1").start();
        while (true) {
            if (threadDemo.getFlag()) {
                System.out.println("end task");
                break;
            }
//            File file = new File("F://text.txt");
        }
    }
}

class ThreadDemo implements Runnable {
    private boolean flag = false;

    @SneakyThrows
    @Override
    public void run() {
        TimeUnit.SECONDS.sleep(1);
        flag = true;
        System.out.println("set flag:" + flag);
    }

    public boolean getFlag() {
        return flag;
    }
}